<template>
	<view class="page">
		<view class="wrapper">
			<view class="card">
				<view class="top">
					<view class="left">
						USDT
						<button class="cu-btn sm margin-left lines-white" @click="sync('usdt')">
							同步区块
						</button>
					</view>
					<view class="right">
						≈￥{{usdt_cny}}
					</view>
				</view>
				
				<view class="btm">
					<image class="img" src="../../static/images/usdt.png" mode="aspectFit"></image>
					<view class="left">
						<view class="text-gray">
							可用
						</view>
						<view class="text-white">
							{{userfund.usdt}}
						</view>
					</view>
					<view class="right">
						<view class="text-gray">
							待定
						</view>
						<view class="text-white">
							{{userfund.usdt_freeze}}
						</view>
					</view>
				</view>
				
				<view class="btns margin-tb">
					<button class="cu-btn lines-green" @click="goto('/pages/mine/recharge?type=usdt')">
						充币
					</button>
					<button class="cu-btn lines-white" @click="goto('/pages/mine/extract?type=usdt')">
						提币
					</button>
				</view>
			</view>
			
			<view class="card margin-top">
				<view class="top">
					<view class="left">
						EPC
					</view>
					<view class="right">
						≈￥{{epc_cny}}
					</view>
				</view>
				
				<view class="btm">
					<image class="img" src="../../static/images/epc.png" mode="aspectFit"></image>
					<view class="left">
						<view class="text-gray">
							可用
						</view>
						<view class="text-white">
							{{userfund.epc}}
						</view>
					</view>
					<view class="right">
						<view class="text-gray">
							待定
						</view>
						<view class="text-white">
							{{userfund.epc_freeze}}
						</view>
					</view>
				</view>
				
				<view class="btns margin-tb">
					<button class="cu-btn lines-green" @click="goto('/pages/mine/recharge?type=epc')">
						充币
					</button>
					<button class="cu-btn lines-white" @click="goto('/pages/mine/extract?type=epc')">
						提币
					</button>
				</view>
			</view>
			
			<scroll-view scroll-x class="bg-white nav">
				<view class="flex text-center">
					<view
						class="cu-item"
						:class="index==TabCur?'active cur':''"
						v-for="(item,index) in tabList"
						:key="index"
						@tap="tabSelect"
						:data-id="index">
							{{item}}
					</view>
				</view>
			</scroll-view>
			
			<view class="list" v-show="TabCur == 0">
				<view class="row" v-for="(i,k) in recharge" :key="k">
					<view class="time">
						{{i.created_at}} &nbsp&nbsp&nbsp&nbsp {{i.coin_type}}
					</view>
					
					<view class="change">
						+{{i.amount}}
					</view>
				</view>
			</view>
			
			<view class="list" v-show="TabCur == 1">
				<view class="row" v-for="(i,k) in draw" :key="k">
					<view class="time">
						{{i.created_at}} &nbsp&nbsp {{i.coin_type}} &nbsp&nbsp {{i.status == 0 ? '处理中' : (i.status == 1 ? '成功' : '失败')}}
					</view>
					
					<view class="change">
						{{i.amount}}
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				TabCur: 0,
				scrollLeft: 0,
				tabList: ['充币记录', '提币记录'],
				userfund: {},
				recharge: [],
				draw: [],
				usdt_cny: 0,
				epc_cny: 0
			};
		},
		onLoad() {
			this.getWallet();
			this.getRecharge();
			this.getDraw();
		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			goto(path) {
				uni.navigateTo({
					url: path,
					animationType: 'slide-in-right',
					animationDuration: 300
				})
			},
			getWallet() {
				this.$u.get('/finance/wallet').then(res => {
					this.userfund = res.data.result.userfund
					this.epc_cny = res.data.result.epc_cny
					this.usdt_cny = res.data.result.usdt_cny
				})
			},
			getRecharge() {
				this.$u.get('/finance/recharge/record').then(res => {
					this.recharge = res.data.result.record
				})
			},
			getDraw() {
				this.$u.get('/finance/draw/record').then(res => {
					this.draw = res.data.result.record
				})
			},
			sync(type) {
				uni.showLoading({
					mask: true
				})
				this.$u.get('/finance/sync/'+type).then(res => {
					this.getWallet();
					this.getRecharge();
					this.getDraw();
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btns {
		display: flex;
		justify-content: space-around;
		.cu-btn {
			padding: 30rpx 100rpx;
		}
	}
	
	.nav {
		margin-top: 50rpx;
		background: #242644;
		color: #B9B9C1;
		.active {
			color: #00D388;
		}
	}
	
	.card {
		color: #fff;
		background: #1B1B3B;
		padding: 20rpx 30rpx;
		border-radius: 20rpx;
		margin-bottom: 50rpx;
		line-height: 2;
		.top {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			.left {
				font-size: 40rpx;
				font-weight: bold;
				display: flex;
				align-items: center;
			}
			.right {
				color: #00CE89;
			}
		}
		.btm {
			display: flex;
			align-items: center;
			.img {
				width: 80rpx;
				height: 80rpx;
				flex: 1;
				margin-right: 20rpx;
			}
			.left {
				flex: 3;
				display: flex;
				flex-flow: column;
			}
			.right {
				flex: 3;
				display: flex;
				flex-flow: column;
				align-items: flex-end;
			}
		}
	}
	
	.list {
		padding: 60rpx 0 100rpx 0;
	}
	.row {
		display: flex;
		justify-content: space-between;
		margin-bottom: 20rpx;
		.change {
			color: #00D388;
		}
	}
</style>